/*
** Copyright (C) 2009 Joshua Brent Marsh <joshua@icub3d.com>
**  
** This file is part of icub3d-adt
**
** icub3d-adt is free sofware; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**  
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**  
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**  
*/

/* $Id: btree_funcs.h 36 2009-11-02 15:06:50Z joshua@icub3d.com $ */

#ifndef ICUB3D_BTREE_FUNCS_H
#define ICUB3D_BTREE_FUNCS_H 1

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "btree.h"

struct btree_node * new_node (void *, struct btree_node *,
			     struct btree_node *);

/* Probe for a node. */
struct btree_node * probe (Btree *, void *);

/* Finds the first or last item in the sorted tree. */
struct btree_node * find_min (Btree *btree);
struct btree_node * find_max (Btree *btree);

/* Removes the node from the tree and returns the data. */
void * remove_node (Btree *btree, struct btree_node *cur);

/* Some simple accessors to make code more readable. */
struct btree_node * parent (struct btree_node *);
struct btree_node * grandparent (struct btree_node *);
struct btree_node * sibling (struct btree_node *);
struct btree_node * uncle (struct btree_node *);

/* Btree rotations. */
void rotate_left (Btree *, struct btree_node *);
void rotate_right (Btree *, struct btree_node *);
void replace_node (Btree *, struct btree_node *,
		   struct btree_node *);

#endif /* ICUB3D_BTREE_FUNCS_H */
